
# -*- coding: utf-8 -*-

import os
import time
import random
import PathConfig

# 改变文件的时间


# H 和 M 文件的创建时间一样
dictName = {} 

def updateDate(filepath, fName):
	randomDay = random.randint(1,60)
	atime = 0;
	mtime = 0;

	fileKey = fName[0:-2]
	if fileKey in dictName:
		timeTemp = int(dictName[fileKey])
		mtime = timeTemp
		tempNow = int(time.time())
		atime = mtime + random.randint(0,tempNow-timeTemp)
	else :
		timeTemp = int(time.time())
		mtime = timeTemp - random.randint(3600,86400*randomDay)
		dictName[fileKey] = mtime
		randomATime = random.randint(1,randomDay)
		atime = mtime + random.randint(10,86400*randomATime)
		
	# 改变文件的时间
	os.utime(filepath, (atime, mtime))




def updateDate1(filepath, fName):

	atime = 0;
	mtime = 0;

	fileKey = fName[0:-2]
	if fileKey in dictName:
		timeTemp = int(dictName[fileKey])
		tempNow = int(time.time())
		mtime = timeTemp + random.randint(0,tempNow-timeTemp)
		atime = mtime
		
		os.utime(filepath, (atime, mtime))
	

def traverse(file_dir):
    fs = os.listdir(file_dir)
    for dir in fs:
    	if dir.startswith('.'):
			#过滤隐藏
			continue

        tmp_path = os.path.join(file_dir, dir)
        if not os.path.isdir(tmp_path):
			updateDate(tmp_path,dir)
			updateDate1(tmp_path,dir)

        else:
            # 是文件夹,则递归调用
            traverse(tmp_path)



def main():
	traverse(PathConfig.rub_filepath)
	print('Finish done')

if __name__ == '__main__':
	main()



